package com.kqkj.dyrule.marketing.demo;

import org.apache.commons.io.FileUtils;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.internal.utils.KieHelper;

import java.io.File;
import java.io.IOException;

public class DroolsDemo {
    public static void main(String[] args) throws IOException {
        String drlString = FileUtils.readFileToString(new File("D:\\项目\\zenniu_marketing\\rule_engine\\src\\main\\resources\\rules\\rule1.drl"), "utf-8");

        //用规则字符串来构造一个kieSession
        KieHelper kieHelper = new KieHelper();
        kieHelper.addContent(drlString, ResourceType.DRL);
        KieSession kieSession = kieHelper.build().newKieSession();

        Student student = new Student(38);
        Teacher teacher = new Teacher(20);

        //调用引擎规则
        kieSession.insert(student);
        kieSession.insert(teacher);
        kieSession.fireAllRules();
        kieSession.dispose();
        System.out.println("年龄之和"+student.getAge());
    }

}
